<template>
  <div>
    <el-table border :data="refunds">
      <el-table-column label="退货订单号" prop="returnNumber">
        <template slot-scope="scope">
          <el-link type="primary" @click="openReturn(scope.row.id)" >{{scope.row.returnNumber}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" prop="detail.orders.pid"></el-table-column>
      <el-table-column label="货物状态" >
        <template slot-scope="scope">
          <el-tag  v-if="scope.row.shopState==0" type="danger"> 未收到货 </el-tag>
          <el-tag  v-if="scope.row.shopState==1" > 已收到货 </el-tag>
          <el-link type="primary" @click="showPicture(scope.row.id)" >查看图片</el-link>
        </template>
      </el-table-column>
      <el-table-column label="退款金额(元)" prop="money"></el-table-column>
      <el-table-column label="操作" >
        <template  slot-scope="scope">
          <el-button size="mini" type="success" @click="audit(scope.row.id,1)">允许通过</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-row class="mytop" v-if="refunds.length>0">
        <el-col :span="4">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageno"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-dialog
        :visible.sync="dialogVisible"
        :before-close="handleClose"
        width="50%">
        <return-detail ref="returnDetail"></return-detail>
      </el-dialog>
      <el-dialog
        :visible.sync="dialogVisible2"
        :before-close="handleClose2"
        width="50%">
        <return-picture ref="returnPicture"></return-picture>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import ReturnDetail from "./ReturnDetail";
  import ReturnPicture from "./ReturnPicture";
    export default {
        name: "checkReturn",
        data(){
          return{
            refunds: [],
            pageno: 1,
            pagesize: 5,
            total: 1,
            dialogVisible:false,
            dialogVisible2:false,
          }
        },
        methods: {
          getData() {
            let refund={
              isAudit:0,//未审核
              isDelete:0//未被删除
            }
            var params = {};
            params["pageno"] = this.pageno;
            params["pagesize"] = this.pagesize;
            Object.keys(refund).forEach(item => {
              params[item] = refund[item];
            });
            this.$axios
              .get("queryAllReturn.action",{params: params})
              .then(res=>{
                this.refunds=res.data.records;
                this.total = res.data.total;
              })
              .catch(err=>{this.$message.error(err)})
          },
          showPicture(id){
            this.dialogVisible2=true;
            this.$nextTick(item => {
              this.$refs.returnPicture.getData(id);
            });
          },
          audit(id,isAudit){
            let refund={
              id:id,
              isAudit:isAudit
            }
            //调用异步，进行审核
            this.$axios.put("refund.action",refund)
              .then(res=>{
                if(res.data.x){
                  this.$message.success(res.data.msg);
                }else {
                  this.$message.error(res.data.msg);
                }
                //重新查询一次数据
                this.getData();
              })
              .catch(err=>{
                this.$message.warning(err);
                alert(err);
              })
          },
          handleClose2(){
            this.$refs.returnPicture.cancel();
          },
          openReturn(id){
            //打开退货详情表
            this.dialogVisible=true;
            this.$nextTick(item => {
              this.$refs.returnDetail.getData(id);
            });
          },
          handleClose() {
            this.$nextTick(item => {
              this.$refs.returnDetail.cancel();
            })
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getData();
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getData();
          },
        },
        components:{
          ReturnDetail,ReturnPicture
        },
        created() {
          this.getData();
        }
    }
</script>

<style scoped>

</style>
